﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ChurchData.Business;

namespace ChurchData
{
    public partial class MainForm : ChurchForm
    {
        public MainForm()
        {
            InitializeComponent();
        }

        #region Menu Click Events

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void lookupPeopleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool frmAlreadyOpen = false;
            if (this.MdiChildren.Count() > 0)
            {
                for (int x = 0; x < this.MdiChildren.Count(); x++)
                {
                    if (((ChurchForm)this.MdiChildren[x]).Title == "Look Up")
                    {
                        ((ChurchForm)this.MdiChildren[x]).Focus();
                        frmAlreadyOpen = true;
                    }
                }
            }

            if (!frmAlreadyOpen)
            {
                PeopleLookUpForm frmLookUp = new PeopleLookUpForm();
                frmLookUp.MdiParent = this;
                frmLookUp.Show();
                frmLookUp.SetFocus();
            }
        }

        private void manageUsersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool frmAlreadyOpen = false;
            if (this.MdiChildren.Count() > 0)
            {
                for (int x = 0; x < this.MdiChildren.Count(); x++)
                {
                    if (((ChurchForm)this.MdiChildren[x]).Title == "UserForm")
                    {
                        ((ChurchForm)this.MdiChildren[x]).Focus();
                        frmAlreadyOpen = true;
                    }
                }
            }

            if (!frmAlreadyOpen)
            {
                UserForm frmUser = new UserForm();
                frmUser.MdiParent = this;
                frmUser.Show();
            }
        }

        private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangePasswordForm frm = new ChangePasswordForm();
            frm.ShowDialog();
        }

        #endregion Menu Click Events

        #region Form Open Methods
        public void OpenPeopleMain(int peoplePK)
        {
            bool frmAlreadyOpen = false;

            if (peoplePK != -1)
            {
                if (this.MdiChildren.Count() > 0)
                {
                    for (int x = 0; x < this.MdiChildren.Count(); x++)
                    {
                        if (((ChurchForm)this.MdiChildren[x]).Title.IndexOf("(" + peoplePK.ToString() + ")") > -1)
                        {
                            ((ChurchForm)this.MdiChildren[x]).Focus();
                            frmAlreadyOpen = true;
                        }
                    }
                }
            }

            if (!frmAlreadyOpen)
            {
                PeopleMain frmPM = new PeopleMain(peoplePK);
                frmPM.MdiParent = this;
                frmPM.Show();
                frmPM.Focus();
            }
        }

        #endregion Form Open Methods

        private void associationsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LKTableMaintenanceForm maintenanceForm = new LKTableMaintenanceForm(new LKAssociationBO());
            maintenanceForm.HeaderText = "Association";
            maintenanceForm.LabelText = "Association";
            maintenanceForm.GridColumnText = "Association";

            maintenanceForm.ShowDialog();
        }

        private void dateTypesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LKTableMaintenanceForm maintenanceForm = new LKTableMaintenanceForm(new LKDateTypeBO());
            maintenanceForm.HeaderText = "Date Type";
            maintenanceForm.LabelText = "Date Type";
            maintenanceForm.GridColumnText = "Date Type";

            maintenanceForm.ShowDialog();
        }

        private void keywordsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LKTableMaintenanceForm maintenanceForm = new LKTableMaintenanceForm(new LKKeywordBO());
            maintenanceForm.HeaderText = "Keywords";
            maintenanceForm.LabelText = "Keywords";
            maintenanceForm.GridColumnText = "Keywords";

            maintenanceForm.ShowDialog();

        }

        private void maritalStatusToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LKTableMaintenanceForm maintenanceForm = new LKTableMaintenanceForm(new LKMaritalStatusBO());
            maintenanceForm.HeaderText = "Marital Status";
            maintenanceForm.LabelText = "Marital Status";
            maintenanceForm.GridColumnText = "Marital Status";

            maintenanceForm.ShowDialog();
        }

        private void relationshipTypesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LKTableMaintenanceForm maintenanceForm = new LKTableMaintenanceForm();
            maintenanceForm.HeaderText = "Relationship Type";
            maintenanceForm.LabelText = "Relationship Type";
            maintenanceForm.GridColumnText = "Relationship Type";

            maintenanceForm.ShowDialog();
        }

        private void sqlUtilityToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Utility.SqlForm frm = new ChurchData.Utility.SqlForm();
            frm.Show();
        }

        private void labelsByKeywordsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO: Labels by keywords report menu option
        }

        private void eBulletinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EBulletin.EBulletinSignups frm = new ChurchData.EBulletin.EBulletinSignups();
            frm.MdiParent = this;
            frm.Show();
        }

        private void eBulletinSendToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EBulletin.EBulletinSend frm = new ChurchData.EBulletin.EBulletinSend();
            frm.MdiParent = this;
            frm.Show();
        }
    }//class
}
